// alert("inside main home.js");

Ext.Loader.setConfig({
			enabled : true
		});

Ext.Loader.setPath('scribbles', 'js/widgets');
Ext.Loader.setPath('Ext.ux', 'js/ext/ux/');
Ext.require(['Ext.util.History']);
Ext.util.History.init();
function loadScribblesHome() {
	//alert('hi');
	createLayout();

	var token = Ext.util.History.getToken();

	constructToolbar();
	if (isUserLoggedIn()) {
		loadProfilePanel(context.user.userId);
	} else {
	}
	
	
	openWindow(token);

	// Add the current token to the history
	Ext.util.History.on('change', function(token) {
				// alert("Back button clicked: Token from history -> " + token);
				// alert("hashkey : " + hashkey);
		openWindow(token);
	});
}

function openWindow(token) {
	addWindow(token);
	
/*	alert('token222: ' + token);
	//alert(token.startsWith("article//view"));
	if (token == "article/upload") {
		//alert("loading : " + token);
		addWindow('UploadArticle', 'article/upload', 'Upload', true);
	} else if (token == "Dropdown") {
		// alert("loading : " + hashkey);
		addWindow('Dropdown', '../jsp/admin/dropdown.jsp', 'Dropdown', true);
	} else if (token == "login") {
		
	} else if (token == "articleSearch/getArticlesResult") {
		addWindow('ArticlesResult', token, token, true);
	} else if (token == "article/view/1") {
		alert('Article View');
		addWindow('ArticleView', token, 'Article', true);
	}
	else {

	}*/
	
}

function addTokenToHistory(token) {
	var oldtoken = Ext.util.History.getToken();
	var newtoken = token;
	// alert("Old token - " + oldtoken + "--" + "New Token - " + newtoken);
	if (oldtoken === null || oldtoken.search(newtoken) === -1) {
		Ext.History.add(newtoken);
	}
}